package com.itheima.service.impl;

import cn.hutool.core.util.ArrayUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.entity.Banner;
import com.itheima.mapper.BannerMapper;
import com.itheima.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BannerServiceImpl implements BannerService {
    @Autowired
    private BannerMapper bannerMapper;

    @Override
    public PageInfo<Banner> findByPage(int pageNum, int pageSize, String title) {
        PageHelper.startPage(pageNum, pageSize);
        title = (title != null ? title.trim() : title);
        List<Banner> list = bannerMapper.findByPage(title);
        return new PageInfo<>(list);
    }

    @Override
    public Banner findById(Integer id) {
        return bannerMapper.findById(id);
    }

    @Override
    public void save(Banner banner) {
        bannerMapper.save(banner);
    }

    @Override
    public List<Banner> findAll() {
        return bannerMapper.findAll();
    }

    @Override
    public void update(Banner banner) {
        bannerMapper.update(banner);
    }

    @Override
    public void deleteById(Integer id) {
        bannerMapper.deleteById(id);
    }

    @Override
    public void deleteBatch(Integer[] ids) {
        if (ArrayUtil.isNotEmpty(ids)) {
            bannerMapper.deleteByIds(ids);
        }
    }
}
